package com.ferry.transport.netty.consumer;

import com.ferry.transport.api.Connection;
import com.ferry.transport.api.UnResolvedAddress;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;

/**
 * Created by daiyong
 */
public abstract class NettyConnection extends Connection {

	private ChannelFuture channelFuture;

	public NettyConnection(UnResolvedAddress address, ChannelFuture channelFuture) {
		super(address);
		this.channelFuture = channelFuture;
	}

	public ChannelFuture getFuture() {
		return channelFuture;
	}

	@Override
	public void operationComplete(final OperationListener operationListener) {
		channelFuture.addListener((ChannelFutureListener) future -> operationListener.complete(future.isSuccess()));
	}
}
